package com.static_exce;

/**
 * @Author WaveHi
 * @Date 6/8/2021 下午 10:15
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class StudentManagement {

    public static void main(String[] args) {

        //接收学生
        Student[] arr = new Student[5];

        //获取学生
        arr[0] = new Student("Tom",70);
        arr[1] = new Student("John",79);
        arr[2] = new Student("Marry",90);
        arr[3] = new Student("Yue",99);
        arr[4] = new Student("Betty",80);

        //输出平均分
        System.out.println("学生平均分为" + Student.getAvg(arr));

        //输出学生信息
        for(Student s : arr) {

            System.out.println(s);

        }

    }

}

//学生类
class Student {

    private static int no;//学号
    private String name;//姓名
    private int score;//成绩

    public String toString() {

        return "Student[" + "no = " + no + ",name = " + name + ",score = " + score + "]";

    }

    public Student() {

        no++;

    }

    public Student(String name,int score) {

        no++;
        this.name = name;
        this.score = score;

    }

    public void setNo(int no) {

        this.no = no;

    }

    public int getNo() {

        return no;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getName() {

        return name;

    }

    public void setScore(int score) {

        this.score = score;

    }

    public int getScore() {

        return score;

    }

    /**
     * 计算学生平均分
     *@param arr 学生
     *@return 平均分
     */
    public static int getAvg(Student[] arr) {

        //接收学生总分
        int sum = 0;

        //计算总分
        if(arr != null) {

            for(Student s : arr) {

                sum += s.getScore();

            }

        }

        if(no > 0) {

            return sum / no;

        }

        return 0;

    }



}